<?php
    //用来更新的
   $id=$_GET['id'];
   $connect=mysql_connect("localhost","root","192510");
   mysql_select_db("news",$connect);
   $sql="select * from mygroup where id=$id";
   $result=mysql_query($sql);
   $row=mysql_fetch_array($result);
   //得到checkbox中的值
   $sql2="select * from wangzhan";
   $result2=mysql_query($sql2);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="time/jquery.datetimepicker.css"/>
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
<script src="time/jquery.js"></script>
<script src="time/jquery.datetimepicker.js"></script>
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">兴趣群管理</a></li>
	<?php
	  if($id==null){
	?>
	 <li><a href="#">添加群</a></li>
    <?php	
	  }else{
    ?>
	 <li><a href="#">编辑群</a></li>
    <?php	
	  }
	?>
   
    </ul>
    </div>
    
    <div class="formbody">
    
    <div class="formtitle"><span>基本信息</span></div>
    
    <ul class="forminfo">
    <li><label>群名称</label><input  type="text" name="name" id="name"  onblur="qun_name();"  class="dfinput"  value="<?php echo $row['name'];?>"/><i  style="margin-right:8px;display:none;" id="yz_qun_name">群名称不能为空</i></li>
    <li><label>推送方式</label><cite><input type="radio" type="radio" name="send_status" id="send_status" value="0" <?php if($row['send_status']==0){echo "checked=checked";}?>/>定时发送 &nbsp;&nbsp;每天<input type="text" id="send_time" value="<?php echo $row['send_time'];?>"/>点发送</cite></li>
	<li><input type="radio" type="radio" name="send_status" id="send_status" value="1" style="margin-left:85px;" <?php if($row['send_status']==1){echo "checked=checked";}?>/>立即发送</li>
    <li><label>邮件标题</label><cite><input class="dfinput" type="test" name="email_title" id="email_title" size="42"   value="<?php echo isset($row['email_title'])?$row['email_title']:'云盾新闻中心订阅新闻';?>"></cite></li>
    <li><label>是否接收空邮箱</label><cite>	<input type="radio" name="null_email" id="null_email" value="0" <?php if($row['null_email']==0){echo "checked=checked";}?>>是</input>
		                                    <input type="radio" name="null_email" id="null_email" value="1" <?php if($row['null_email']==1){echo "checked=checked";}?>>否</input></cite></li>
    <li><label>发送权限</label><cite>[请用换行符区分关键字的过滤]</cite></li>
    <li><label>标题关键字</label><textarea name="g_title" id="g_title" style="width: 350px;height: 50px;" name="" cols="" rows="" class="textinput"><?php echo $row['g_title'];?></textarea></li>
	<li><label>作者关键字</label><textarea name="g_author" id="g_author" style="width: 350px;height: 50px;" name="" cols="" rows="" class="textinput"><?php echo $row['g_author'];?></textarea></li>
	<li><label>来源网站</label>
	<table style="border-collapse:collapse;border:1px solid gray ; width:400px;heigth:100px;">
	
    <?php
		 
		 while($row2=mysql_fetch_array($result2)){
				   
    ?>
		   
		<tr>
	    <td><input type="checkbox" name="g_web" checked="checked" id="g_web<?php echo $row2['id'];?>" value="<?php echo $row2['id'];?>"/></td>
		<td><?php echo $row2['name'];?></td>
		</tr>
		  
    <?php				 
		}
    ?>
	    <input type="hidden" id="hiddenid" value="<?php echo isset($row)?$row['id']:'-1'; ?>">
	</table> 
	
	
	</li>
	<li><label>&nbsp;</label><input name="" type="button" class="btn" onclick="jianqun();" value="确认保存"/>
    </ul>
    </div>
</body>

</html>
<script>
    $('#send_time').datetimepicker({
		minDate:0,
		//minTime:0,
	});

    function qun_name(){
		var name=$("#name").val();
		if(name==null||name.length==0){
			$("#yz_qun_name").show();
		
		}else{
		
			$("#yz_qun_name").hide();
			
		}
	
   }

	 function jianqun(){
	     
	 	 var name=$("#name").val();
		
		 if(name==null||name.length==0){
			 
			 alert("群名称不能为空");
			 window.location.href="../insert/insert_group.php";
			 
		 }else{
			 
		 var id=$("#uid").val();
	     var g_web=[];
	     var email_title=$("#email_title").val();
		 var send_status= $('input:radio[name="send_status"]:checked').val();
		 var send_time=$("#send_time").val();
		 var g_title=$("#g_title").val();
         var g_author=$("#g_author").val();
		 var null_email=$('input:radio[name="null_email"]:checked').val();
		 $('input[name="g_web"]:checked').each(function(){ 
            g_web.push($(this).val());  
         }); 
		 
	  $.post("insert_group_commit.php",
		  { 
		     id:id,
			 name:name,
			 send_status:send_status,
			 send_time:send_time,
			 g_title:g_title,
			 g_author:g_author,
			 g_web:g_web,
			 email_title:email_title,
			 null_email:null_email
		  },
		  function(data){
			  alert("操作成功");
			  window.location.href="select_group.php";
		      // $("#name").val(data.name);
			  // $("send_status").val(data.send_status);
			  // $("#send_time").val(data.send_time);
			  // $("#g_title").val(data.g_title);
			  // $("#g_author").val(data.g_author);
			  // $("#g_web").val(data.g_web);
			  // $("#email_title").val(data.email_title);
			  // $("#gid").val(data.id);
			  // $("#hiddenid").val(data.id);
		 }) 
			 
		 }
	  
	 } 

$(document).ready(function(){
	    //选择框中的的所有的value
	    var g_web=[];
		$('input[name="g_web"]:checked').each(function(){ 
           g_web.push($(this).val());  
        });
	
		//数据库中需要选中的
	    var ss="<?php $ss=$row['g_web']; echo $ss?>";
		var array=new Array();
		array = ss.split(',');
		
		var id="<?php echo intval($id);?>";
		
		if(id!=0){
		   for(var i=0;i<g_web.length;i++){
				$("#g_web"+g_web[i]).attr("checked",false);
		   }
		   
			
			for(var j=0;j<array.length;j++){
				$("#g_web"+array[j]).prop("checked",true);
		    }
		   
        } 
		
})

</script>